package com.citcc.api.netty.bean;



import org.jboss.netty.buffer.ChannelBuffer;

public class ConsuMessage {
    public static final int MSG_HEAD_1 = 0X75;
    public static final int MSG_HEAD_2 = 0X72;
    public static final int MSG_END = 0X68;
    
    
    
    
    //-----------协成-------------------------
    public static final int XC_MSG_HEAD_1 = 0x55;
    public static final int XC_MSG_HEAD_2 = 0xAA;
    public static final int XC_MSG_END = 0x0D;

    //报文中除数据体外，固定的数据长度
    public static final int MSG_FIX_LENGTH = 7;

    //报文序列号，自增。
    private static int internalMsgNo = 0;
    private long msgLength;
    private long deviceNo;
    private int msgGesscenterId;
    private int msgId;
    private int source;//枪号
    private int transType;
    private int type;
    private ChannelBuffer msgBody;
    private int versionFlag = 0x01070502;//版本号
    private int loginState;
    private int heartState;
    private String phone;
    private String mode;//充电模式 
    private long time;//单位秒
    private long money;//单位分
    private long dl;//单位0.01kw/h
    
    private String id;
    
    private String terminalNo;
    private long msgQfLength;
    private int no;//序号
    private int dataObj;
    
    
    

    //下行报文标识，值为1时，代表发送的数据；默认为0，代表接收的报文
    //private int downFlag = 0;

    
    public int getNo() {
		return no;
	}



	public void setNo(int no) {
		this.no = no;
	}



	public int getDataObj() {
		return dataObj;
	}



	public void setDataObj(int dataObj) {
		this.dataObj = dataObj;
	}



	public String getId() {
		return id;
	}

	

	public void setId(String id) {
		this.id = id;
	}
	
	

	public ConsuMessage() {
		//下行报文需要填充报文序列号
        synchronized((Integer)internalMsgNo) {
            if(internalMsgNo == 0xFF){
                internalMsgNo = 0;
            }
            no = ++internalMsgNo;
        }
	}



	public ConsuMessage(int msgId){
		//下行报文需要填充报文序列号
        synchronized((Integer)internalMsgNo) {
            if(internalMsgNo == 0xFF){
                internalMsgNo = 0;
            }
            no = ++internalMsgNo;
        }
	}



    public long getMsgLength() {
        return msgLength;
    }

    public void setMsgLength(long msgLength) {
        this.msgLength = msgLength;
    }

    public int getMsgId() {
        return msgId;
    }

    public void setMsgId(int msgId) {
        this.msgId = msgId;
    }

    public long getMsgGesscenterId() {
        return msgGesscenterId;
    }



    public ChannelBuffer getMsgBody() {
        return msgBody;
    }

    public void setMsgBody(ChannelBuffer msgBody) {
        //System.out.println("0x"+Integer.toHexString(this.msgId)+": "+msgBody.capacity()+" 字节数据体.");
        this.msgBody = msgBody;
    }

    public static int getInternalMsgNo() {
        return internalMsgNo;
    }

    public static void setInternalMsgNo(int internalMsgNo) {
        ConsuMessage.internalMsgNo = internalMsgNo;
    }

    public long getDeviceNo() {
        return deviceNo;
    }

    public void setDeviceNo(long deviceNo) {
        this.deviceNo = deviceNo;
    }

    public void setMsgGesscenterId(int msgGesscenterId) {
        this.msgGesscenterId = msgGesscenterId;
    }

    public int getVersionFlag() {
        return versionFlag;
    }

    public void setVersionFlag(int versionFlag) {
        this.versionFlag = versionFlag;
    }

    public int getSource() {
        return source;
    }

    public void setSource(int source) {
        this.source = source;
    }

    public int getTransType() {
        return transType;
    }

    public void setTransType(int transType) {
        this.transType = transType;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getLoginState() {
        return loginState;
    }

    public void setLoginState(int loginState) {
        this.loginState = loginState;
    }

    public int getHeartState() {
        return heartState;
    }

    public void setHeartState(int heartState) {
        this.heartState = heartState;
    }
    
    

    public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	

	public String getMode() {
		return mode;
	}

	public void setMode(String mode) {
		this.mode = mode;
	}

	

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
	}
	
	

	public long getMoney() {
		return money;
	}

	public void setMoney(long money) {
		this.money = money;
	}
	
	

	public long getDl() {
		return dl;
	}

	public void setDl(long dl) {
		this.dl = dl;
	}
	
	

	public String getTerminalNo() {
		return terminalNo;
	}

	public void setTerminalNo(String terminalNo) {
		this.terminalNo = terminalNo;
	}
	
	

	public long getMsgQfLength() {
		return msgQfLength;
	}

	public void setMsgQfLength(long msgQfLength) {
		this.msgQfLength = msgQfLength;
	}

	@Override
    public String toString() {
        return "Message{" +
                "msgLength=" + msgLength +
                ", deviceNo=" + deviceNo +
                ", msgGesscenterId=" + msgGesscenterId +
                ", msgId=" + msgId +
                ", source=" + source +
                ", transType=" + transType +
                ", type=" + type +
                ", msgBody=" + msgBody +
                ", versionFlag=" + versionFlag +
                '}';
    }
	
	public static void main(String[] args) {
		ConsuMessage msg = new ConsuMessage();
		System.out.println(msg.getNo());
		ConsuMessage msg1 = new ConsuMessage();
		System.out.println(msg1.getNo());
		ConsuMessage msg2 = new ConsuMessage();
		System.out.println(msg2.getNo());
	}
}
